﻿$(document).ready(function () {

    $("a[rel^='prettyPhoto']").click(function (event) {
        var tag = this.rel;
        var ablum = tag.substr(tag.indexOf('[') + 1, tag.lastIndexOf(']') - tag.indexOf('[') - 1);


        if (!$("#" + ablum).hasClass('ablumhasdownloaded')) {
            $.ajax({ url: '/album/AlbumPhotoJson', data: { albumId: ablum }, type: "POST", dataType: "json", success: function (data) {
                for (i in data) $('body').append('<a href="' + data[i].href + '" rel="prettyPhoto[' + ablum + ']" title="' + data[i].title + '"></a>');
                $("a[rel='prettyPhoto[" + ablum + "]']").prettyPhoto({ social_tools: false, animation_speed: 'normal', theme: 'facebook', slideshow: 3000, autoplay_slideshow: false });
                $("#" + ablum).addClass('ablumhasdownloaded');
                $("#" + ablum).click();
            }
            });
            event.preventDefault();
        }
    });


});   //end of documment

